package models

import (
	"CMETO/utils"
	"time"
)

// 课程表
type Course struct {
	// 字典
	Id int `json:"id" gorm:"column:id;type:int;auto_increment;primary_key;"`
	// 课程名称
	Name string `json:"name" gorm:"column:name;type:varchar(40);"`
	// 分类id
	Tid int `json:"tid" gorm:"column:tid;type:int"`
	// 封面地址Url
	CoverUrl string `json:"cover_url" gorm:"column:cover_url;type:varchar(250);"`
	// 视频Url
	VideoUrl string `json:"video_url" gorm:"column:video_url;type:varchar(250);"`
	// 详情图片Url
	DetailUrl string `json:"detail_url" gorm:"column:detail_url;type:varchar(250);"`
	// 课程描述
	Description string `json:"description" gorm:"column:description;type:varchar(120);"`
	// 课程开始时间
	StratTime string `json:"start_time" gorm:"column:start_time;type:varchar(30);"`
	// 课程结束时间
	EndTime string `json:"end_time" gorm:"column:end_time;type:varchar(30);"`
	// 状态
	Status int `json:"status" gorm:"column:status;type:int;"`
	// 创建时间
	CreateTime string `json:"create_time" gorm:"column:create_time;type:varchar(30);"`
	// 是否删除
	IsDelete int    `json:"is_delete" gorm:"column:is_delete;type:int;"`
	Teacher  []User `json:"teacher" gorm:"many2many:course_teachers;"`
}

// 商品表联合分类表查询
type CourseFormat struct {
	*Course
	Tname       string `json:"tname"`
	Teacher_ids []int  `json:"teacher_ids" gorm:"-"`
}

// 插入一批课程
func InsertMockCourse() {
	DB.Model(&Course{}).Create([]Course{
		{Id: 1, Name: "2024一期《通俗唱法入门》", Tid: 1, CoverUrl: "http://resource.shuonihao.cn/cmeto/course/rolling_cover.jpg", VideoUrl: "http://resource.shuonihao.cn/cmeto/course/rolling.mp4", DetailUrl: "http://resource.shuonihao.cn/cmeto/course/rolling_detail.jpg", Description: "2024一期", StratTime: utils.TimeFormatter(time.Now()), EndTime: utils.TimeFormatter(time.Now().AddDate(1, 0, 0)), Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
		{Id: 2, Name: "2024二期《通俗唱法入门》", Tid: 2, CoverUrl: "http://resource.shuonihao.cn/cmeto/course/rolling_cover.jpg", VideoUrl: "http://resource.shuonihao.cn/cmeto/course/rolling.mp4", DetailUrl: "http://resource.shuonihao.cn/cmeto/course/rolling_detail.jpg", Description: "2024一期", StratTime: utils.TimeFormatter(time.Now()), EndTime: utils.TimeFormatter(time.Now().AddDate(1, 0, 0)), Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
	})
}
